package com.stir.cgt.ajm.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.VerticalPanel;


public class BucketLabel extends CaptionPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name;
	private final RadioButton niceRadio = new RadioButton("buttons", "Good");
	private final RadioButton nastyRadio = new RadioButton("buttons", "Bad");

	public BucketLabel(TreeLink link, Test test) {
		super("A label");
		initComponents();
	}

	public void setText(String text){
		name = text;
	}

	public void setNice(boolean nice){
		if (nice){
			DOM.setStyleAttribute(this.getElement(),"border","3px solid #0f0");
			nastyRadio.setValue(false);
		}
		else {
			DOM.setStyleAttribute(this.getElement(),"border","3px solid #f00");
			niceRadio.setValue(false);
		}
	}

	private void initComponents() {
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.add(niceRadio);
		vPanel.add(nastyRadio);
		HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.add(new Label("A label"));
		hPanel.add(vPanel);
		
		this.setContentWidget(hPanel);
		this.setSize("300px", "100px");

		DOM.setStyleAttribute(this.getElement(),
		     "border", "3px solid #0f0");
		DOM.setStyleAttribute(this.getElement(),
			     "margin", "10px 10px 10px 10px");
		DOM.setStyleAttribute(this.getContentWidget().getElement(),
		     "margin", "5px 10px 10px 10px");
		DOM.setStyleAttribute(this.getContentWidget().getElement(),
		     "padding", "10px 10px 10px 10px");
		DOM.setStyleAttribute(this.getContentWidget().getElement(),
		     "border", "1px solid #ccf");

		
		// Hook up a handler to the radio buttons
		ClickHandler ch = new ClickHandler() {
			public void onClick(ClickEvent event) {
				if(event.getSource()==niceRadio){
					setNice(true);
				}
				else if(event.getSource()==nastyRadio){
					setNice(false);
				}
			}
		};
		
		niceRadio.addClickHandler(ch);
		nastyRadio.addClickHandler(ch);
		
		

	}
}
